package com.freewater.springboot.demo.aop.advice.afterthrow;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class PersonAspect {

    @Pointcut("execution(* com.freewater.springboot.demo.aop.advice.afterthrow.PersonService.*(..))")
    public void allMethod() {

    }

    // 注意，throwing值为NullPointerException类型的exception，因此也限定了只能拦截抛出异常类型为NullPointerException类的场景
    @AfterThrowing(value = "allMethod() && args(name,age)", throwing = "exception", argNames = "joinPoint,age,name,exception")
    public void beforeAdvice(JoinPoint joinPoint, int age, String name, NullPointerException exception) {
        System.out.println("params age: " + age);
        System.out.println("params name: " + name);
        System.out.println("throw exception:  " + exception);
    }

}
